package com.example.medicinetime;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.GridView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CompletedListActivity extends AppCompatActivity {
    public static final String TAG= "CompletedListActivity";
    ListView completed_records;
    ListAdapter listAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_completed_list);
        ArrayList<FinishRecord> completed_listall =new ArrayList<>();
        completed_records = (ListView) findViewById(R.id.completed_list);
        DBManager dbManager = new DBManager(this);
        for(FinishRecord finishRecord : dbManager.listAll_completed()){
            FinishRecord item = new FinishRecord(finishRecord.getF_medicien_name(),finishRecord.getFinishDate(),finishRecord.getFinishtime(),finishRecord.getF_dosis());
            completed_listall.add(item);
        }
        Collections.reverse(completed_listall);

        //自定义Adapter
        listAdapter = new ListAdapter(this,R.layout.list_item,completed_listall);
        completed_records.setAdapter(listAdapter);

        //返回
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);


    }

    //监听返回按钮，若点击返回则关闭当前Activity
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
            return true;
        }
        super.onOptionsItemSelected(item);
        return true;
    }
}